// 权限菜单
module.exports = app => {
    const DataTypes = app.Sequelize;
    const SysRoleMenu = app.model.define('SysRoleMenu', {
        id: {
            type: DataTypes.INTEGER(11).UNSIGNED,
            allowNull: false,
            primaryKey: true,
            autoIncrement: true,
        },
        role_id: {
            type: DataTypes.INTEGER(11).UNSIGNED,
            allowNull: false,
            defaultValue: '0',
        },
        cate: {
            type: DataTypes.INTEGER(1).UNSIGNED,
            allowNull: false,
            defaultValue: '0',
            comment: '0=>商城管理后台, 1=>为分系统预留能力'
        },
        menu_id: {
            type: DataTypes.INTEGER(11).UNSIGNED,
            allowNull: false,
            defaultValue: '0',
        },
        shop_id: {
            type: DataTypes.INTEGER(11),
            allowNull: true,
            defaultValue: null,
            comment: '商家ID，预留SASS功能'
        },
        is_delete: {
            type: DataTypes.INTEGER(1).UNSIGNED,
            allowNull: false,
            defaultValue: '0',
            comment: '是否删除，0->存在，1->删除'
        },
    }, {
        tableName: 'sys_role_menu'
    });
    SysRoleMenu.associate = function () {
        SysRoleMenu.belongsTo(app.model.SysRole, {
            as: 'Role',
            foreignKey: 'role_id',
            constraints: false,
        });

        SysRoleMenu.belongsTo(app.model.SysMenu, {
            as: 'Menu',
            foreignKey: 'menu_id',
            constraints: false,
        });
    };
    return SysRoleMenu;
};
